package com.xinyue.ext.root;

import java.util.HashMap;
import java.util.Map;

import com.xinyue.ext.data.DaoData;
import com.xinyue.ext.data.EntityData;
import com.xinyue.ext.data.RootData;

public class DaoRoot extends RootContext{
	//私有构造器
	private DaoRoot() {
	}
	//私有内部类
	private static class SingletonHolder{
        private static DaoRoot instance = new DaoRoot();  
    }
	/***
	 * 获得实例对象
	 */
	public static DaoRoot getInstance() {
		return SingletonHolder.instance;
	}
	
	/**
	 * 创建Dao信息
	 */
	@Override
	public void freemarkerData(EntityData entity, RootData data) {
		Map<String, Object> root = new HashMap<String, Object>();
		DaoData dao = entity.getDao();
		
		root.put("package", dao.getDaoPackage());
		root.put("import", dao.getImports());
		root.put("importExt", dao.getImportExt());
		root.put("className", entity.getClassName());
		root.put("beanPackage", entity.getBeanPackage());
		root.put("id", entity.getId());
		root.put("rely", dao.getRely());
		root.put("querys", dao.getQuerys());
		root.put("hqls", dao.getHqls());
		root.put("sqls", dao.getSqls());
		
		String daoPath = pathBuild(dao.getDaoPackage(), entity.getClassName(), dao_);
		String implPath = pathBuild(dao.getDaoPackage(), entity.getClassName(), daoImpl_);
		data.setImplPath(implPath);
		data.setDaoPath(daoPath);
		data.setDaoData(root);
	}
}
